package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.DispatchedBean;
import com.ymatou.iapi.trading.operate.parameter.req.OrderLogisticsInfoPo;
import com.ymatou.iapi.trading.operate.service.DispatchedCall;
import com.ymatou.iapi.trading.operate.service.LogisticsDeliveryService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.BillTypeEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 发货API请求实体 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_Dispatched {

	private static DispatchedBean dispatchedbean;

	private static DispatchedCall dispatchedcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("卖家发货接口");
	}

	@Before
	public void caseUp() {

		dispatchedbean = new DispatchedBean();
		dispatchedcall = new DispatchedCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(dispatchedcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_001() {
		Logger.start(true, "卖家非贝海发货请求成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(false);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Dispatched_002() {
		Logger.start(false, "订单不存在");
		try {
			int orderId = 2001501;
			int sellerId = 288484;
			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.FAILED201, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyIsContains(ECode.FAILED201_MSG_11,
					dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_003() {
		Logger.start(false, "当前订单状态不能发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			/* new OrderCallService().acceptOrder(OrderId, SellerId); */
			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.FAILED201, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyEquals("当前状态2不能发货.", dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Dispatched_004() {
		Logger.start(false, "订单为null");
		try {
			int orderId = 2001501;
			int sellerId = 288484;
			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			// dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.ERROR400, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyIsContains(ECode.ERROR400_MSG_9,
					dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Dispatched_005() {
		Logger.start(false, "操作id为null");
		try {
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = orderService.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId); // 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			// dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_006() {
		Logger.start(false, "当前订单为退货退款中,不能发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);

			Logger.comment("前置数据准备结束");
			// 退货退款同步
			orderService.applySalesRefundRequestInJava(orderId);
			Logger.comment("前置数据准备结束");
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.FAILED201, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ErrStatusNotMatch,
					dispatchedcall.getString("bcode"), "验证bcode");
			Logger.verifyEquals(ECode.FAILED201_MSG_62,
					dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_007() {
		Logger.start(false, "该订单已发货,重复发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			// 商家发货
			orderService.dispatched(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.FAILED201, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyEquals("106", dispatchedcall.getString("bcode"),
					"验证bcode");
			Logger.verifyEquals(orderId + ECode.FAILED201_MSG_66,
					dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_008() {

		Logger.start(true, "订单物流类型为贝海直邮,卖家发货成功");
		try {

			PlaceOrderService.logisticsType = LogisticsTypeEnum.SailProtect;
			// 创建订单
			Logger.comment("前置数据准备");

			new DefaultWapper()
					.executeUpdateSql(String
							.format("update Ymt_OrderIdCardCostInfo set amount='%s' where id=3",
									0));

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(true);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_009() {
		Logger.start(true, "订单物流类型为拼邮发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("autotest 拼邮国内发货");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(false);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_010() {
		Logger.start(true, "订单为锁定中,卖家发货失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			new OrderCallService().markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(false);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.FAILED201, dispatchedcall.getCode(),
					"验证Code");

			Logger.verifyEquals("102", dispatchedcall.getBCode(), "验证bcode");

			Logger.verifyEquals("该订单已被洋码头客服锁定，暂时无法对该订单进行后续操作",
					dispatchedcall.getMsg(), "验证msg");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);

			Logger.verifyEquals(0, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(0, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_012() {
		Logger.start(true, "多物流单号,卖家发货请求成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);

			dispatchedbean.setDeliverSummary(DeliverSummary
					+ ",abcdef,efdsdfsdfs");
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(false);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);

			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

			List<OrderLogisticsInfoPo> orderLogisticsInfoPoList = LogisticsDeliveryService
					.getLogisticsDeliveryByOrderId(orderId);

			for (int i = 0; i < orderLogisticsInfoPoList.size(); i++) {
				OrderLogisticsInfoPo orderLogisticsInfoPo = orderLogisticsInfoPoList
						.get(i);

				Logger.verifyEquals(
						dispatchedbean.getDeliverSummary().split(",")[i],
						orderLogisticsInfoPo.getBillCode(),
						"验证Ymt_OrderLogisticsInfo 表 BillCode");
				Logger.verifyEquals(dispatchedbean.getProvider(),
						orderLogisticsInfoPo.getCompany(),
						"验证Ymt_OrderLogisticsInfo 表 Company");

				Logger.verifyEquals(dispatchedbean.getBillType(),
						orderLogisticsInfoPo.getDeliverType(),
						"验证Ymt_OrderLogisticsInfo 表 deliverType");

				DataUtil.verifyDecimalEquals(dispatchedbean.getWeight(),
						orderLogisticsInfoPo.getWeight(),
						"验证Ymt_OrderLogisticsInfo 表 Weight");

				Logger.verifyEquals(dispatchedbean.getDeliverType().equals("0")
						? false
						: true, orderLogisticsInfoPo.getChinaDeliver(),
						"验证Ymt_OrderLogisticsInfo 表 chinaDeliver");

				Logger.verifyEquals(dispatchedbean.getIsShippedByXlobo(),
						orderLogisticsInfoPo.getOfficialLogistics(),
						"验证Ymt_OrderLogisticsInfo 表 officialLogistics");

				Logger.verifyEquals(false, orderLogisticsInfoPo.getDeleted(),
						"验证Ymt_OrderLogisticsInfo 表 deleted");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_Dispatched_013() {
		Logger.start(false, "物流单号为null");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");
			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.UNKNOW.getValue());
			// 物流单号
			String deliverSummary = TestDataManager.randomStr(10);
			//dispatchedbean.setDeliverSummary(deliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);
			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();
			Logger.verifyEquals(ECode.ERROR400, dispatchedcall.getCode(),
					"验证Code");
			Logger.verifyIsContains("物流单号未提供", dispatchedcall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_014() {
		Logger.start(true, "虚拟商品接单后,卖家发货请求成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			new OrderCallService().acceptOrder(orderId, sellerId);

			Logger.comment("前置数据准备结束");

			// 订单ID
			dispatchedbean.setOrderId(orderId);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 4);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);

			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_015() {
		Logger.start(true, "卖家国内发货请求成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			String DeliverSummary = TestDataManager.randomStr(10);
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("1");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(false);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_016() {
		Logger.start(true, "卖家贝海发货请求成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderService.logisticsType = LogisticsTypeEnum.SailProtect;

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			//String DeliverSummary = TestDataManager.randomStr(10);

			String DeliverSummary = "DB503225245US";

			dispatchedbean.setDeliverSummary(DeliverSummary);

			dispatchedbean.setProviderCode("TY160");

			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);

			dispatchedbean.setSource(1);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(true);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Dispatched_017() {
		Logger.start(true, "卖家贝海发货");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderService.logisticsType = LogisticsTypeEnum.SailProtect;

			PlaceOrderResp placeOrderResp = PlaceOrderService.acceptOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			Logger.comment("前置数据准备结束");

			// 订单类型
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			//String DeliverSummary = TestDataManager.randomStr(10);

			String DeliverSummary = "DB503225242US";

			dispatchedbean.setDeliverSummary(DeliverSummary);

			dispatchedbean.setProviderCode("TY160");

			// 物流公司类型(0-国际物流 1-国内物流)
			dispatchedbean.setDeliverType("0");
			// 订单ID
			dispatchedbean.setOrderId(orderId);
			// 物流公司
			dispatchedbean.setProvider("洋码头官方合作物流（贝海国际速递）");
			// 卖家ID
			dispatchedbean.setSellerUserId(sellerId);

			dispatchedbean.setSource(1);
			// 货物重量
			BigDecimal weight = new BigDecimal(10);
			dispatchedbean.setWeight(weight);

			dispatchedbean.setIsShippedByXlobo(true);

			dispatchedcall.setData(dispatchedbean);
			dispatchedcall.callService();

			Logger.verifyEquals(ECode.SUCCESS, dispatchedcall.getCode(),
					"验证Code");

			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 3);
			m.put("UserId", sellerId);
			m.put("TraddingId", orderId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易表记录");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
